package fr.irit.etracetool.eobjectgraph;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EcoreFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import static org.junit.Assert.*;

public class NodeTest {

	private Node n;
	@Before
	public void setUp() throws Exception {
		EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
		n = new Node(attr);
	}
	
	@Test
	public void getElementTest() {
		assertNotNull(n.getElement());
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void equalsTest() {
		EAttribute attrB = EcoreFactory.eINSTANCE.createEAttribute();
		attrB.setName("A");
		Node n1 = new Node(attrB);
		EAttribute attrA = EcoreFactory.eINSTANCE.createEAttribute();
		attrA.setName("A");
		Node n2 = new Node(attrA);
		assertTrue(n2.equals(n1));
		assertTrue(n1.equals(n2));
	}
	
	@Test
	public void getSuccessorTest() {
		assertNotNull(n.getSuccessor());
	}
	
	@Test
	public void addSuccTest() {
		EAttribute attrA = EcoreFactory.eINSTANCE.createEAttribute();
		attrA.setName("A");
		Node n1 = new Node(attrA);
		EAttribute attrB = EcoreFactory.eINSTANCE.createEAttribute();
		attrB.setName("B");
		Node n2 = new Node(attrB);
		n1.addSucc(n2);
		assertTrue(BipartiteGraph.contains(n1.getSuccessor(), attrB));
		n1.addSucc(n2);
		assertTrue(n1.getSuccessor().size()==1);
	}

}
